package com.jh.fcsm.controller.sys;

import com.github.pagehelper.PageInfo;
import com.jh.fcsm.beans.sys.SysLogOper;
import com.jh.fcsm.beans.sys.vo.SysLogOperExportVo;
import com.jh.fcsm.beans.sys.vo.SysLogOperVo;
import com.jh.fcsm.common.BaseController;
import com.jh.fcsm.common.RestApiResponse;
import com.jh.fcsm.service.sys.SysLogOperService;
import com.jh.fcsm.util.poi.EasyExcelUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户操作日志表
 *
 * @author szx
 * @date 2020-07-07 17:51:45
 */
@RestController
@RequestMapping("/sys/sysLogOper")
@Api(value = "用户操作日志表", tags = "用户操作日志表")
public class SysLogOperController extends BaseController {

    private static final String PER_PREFIX = "btn:sys:operlog:";
    @Autowired
    private SysLogOperService sysLogOperService;

    /**
     * 分页查询用户操作日志表
     *
     * @param sysLogOperVo 用户操作日志表 查询条件
     * @return RestApiResponse<?>
     */
    @PostMapping("/findPageByQuery")
    @ApiOperation(value = "分页查询用户操作日志表", notes = "分页查询用户操作日志表")
    @PreAuthorize("hasAuthority('" + PER_PREFIX + "query')")
    public RestApiResponse<?> findPageByQuery(@RequestBody SysLogOperVo sysLogOperVo) {
        PageInfo<SysLogOper> sysLogOper = sysLogOperService.findPageByQuery(sysLogOperVo);
        return RestApiResponse.ok(sysLogOper);
    }

    /**
     * 导出操作日志
     *
     * @param sysLogOperVo 日志Vo
     * @author szx
     */
    @PostMapping("/export")
    @ApiOperation(value = "导出操作日志", notes = "导出操作日志")
    @PreAuthorize("hasAuthority('" + PER_PREFIX + "export')")
    public void export(SysLogOperVo sysLogOperVo) {
        List<SysLogOperExportVo> list = sysLogOperService.export(sysLogOperVo);
        EasyExcelUtils.exportExcel(list, "导出操作日志结果", SysLogOperExportVo.class, "导出操作日志结果", response);
    }

}
